package cn.drew.org.controller;

import cn.drew.basic.utils.AjaxResult;
import cn.drew.basic.utils.PageList;
import cn.drew.org.domain.SystemDictionaryDetail;
import cn.drew.org.query.SystemDictionaryDetailQuery;
import cn.drew.org.service.SystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class SystemDictionaryDetailController {

    @Autowired
    private SystemDictionaryDetailService systemDictionaryDetailService;

    @GetMapping
    public List<SystemDictionaryDetail> findALl(){
        List<SystemDictionaryDetail> list = systemDictionaryDetailService.findAll();
        return list;
    }

    @GetMapping("/{id}")
    public SystemDictionaryDetail findById(@PathVariable("id") Long id){
        SystemDictionaryDetail systemDictionaryDetail = systemDictionaryDetailService.findById(id);
        return systemDictionaryDetail;
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        if(systemDictionaryDetail.getId() != null){
            systemDictionaryDetailService.update(systemDictionaryDetail);
        }else{
            systemDictionaryDetailService.add(systemDictionaryDetail);
        }

        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult Delete(@PathVariable("id") Long id){
        systemDictionaryDetailService.delete(id);
        System.out.println(id);
        return AjaxResult.success();
    }

//    分页查询
    @PostMapping
    public PageList<SystemDictionaryDetail> queryByPage(@RequestBody SystemDictionaryDetailQuery systemDictionaryDetailQuery){
        System.out.println(systemDictionaryDetailQuery);
        PageList<SystemDictionaryDetail> pageList = systemDictionaryDetailService.queryByPage(systemDictionaryDetailQuery);
        return pageList;
    }

    //批量删除
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        systemDictionaryDetailService.patchDelete(ids);
        return AjaxResult.success();
    }

    //通过departmentid查找员工
    @GetMapping("/findBytypesid/{typesid}")
    public List<SystemDictionaryDetail> findBytypesid(@PathVariable("typesid") Long typesid){
        return systemDictionaryDetailService.findBytypesid(typesid);
    }
    
//    //无线级数
//    @GetMapping("/tree")
//    public List<SystemDictionaryDetail> tree(){
//        List<SystemDictionaryDetail> tree = systemDictionaryDetailService.tree();
//        System.out.println(tree);
//        return SystemDictionaryDetailService.tree();
//
//    }


    
}
